<?php

/*
    Error page class.
    
        Author:     Alfredo Mungo
        License:    LGPL
        Copyright:  2012
*/

class Error {

    /*
        THROWS:
            Exception('Non-integer errorcode'): non-integer error code supplied
            Exception('Headers already sent'): headers already sent
    */
    public static function raise($ecode, $msg = null)
    {
        if(!is_int($ecode))
            throw new Exception('Non-integer errorcode');

        $epage = PHI_ROOTDIR . "/errors/$ecode.php";
        
        if(!file_exists($epage)) {
            $epage = PHI_ROOTDIR . '/errors/error.php';
            define('ERROR_CODE', $ecode);
        }
            
        if(headers_sent())
            throw new Exception('Headers already sent');
        
        if($msg !== null)
            define('ERROR_MESSAGE', $msg);
        
        include $epage;
        exit;
    }
}

?>